//
//  MoreMaterialSelectViewController.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/19.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MoreMaterialSelectViewController.h"

#import "CraftSelectViewController.h"

@interface MoreMaterialSelectViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;

@end

@implementation MoreMaterialSelectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"材质选择";
    
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49)) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
    UIButton *connectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49), ScreenX375(258), ScreenX375(49))];
    connectBtn.backgroundColor = REXADECIMALCOLOR(@"#ff9500");
    [connectBtn setTitle:@"有困难请联系我" forState:UIControlStateNormal];
    [connectBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    connectBtn.titleLabel.font = Kfont(14);
    [self.view addSubview:connectBtn];
    
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(258), SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49), SCREEN_WIDTH - ScreenX375(258), ScreenX375(49))];
    nextBtn.backgroundColor = REXADECIMALCOLOR(@"#ed223b");
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.titleLabel.font = Kfont(14);
    [nextBtn addTarget:self action:@selector(nextStep) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextBtn];
}

- (void)nextStep {
    CraftSelectViewController *vc = [[CraftSelectViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 3) {
        return 2;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"imageCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(100), ScreenX375(44))];
                noteLabel.text = @"箱型图片：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UIImageView *boxImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), ScreenX375(79), ScreenX375(79))];
                boxImage.layer.cornerRadius = ScreenX375(5);
                boxImage.clipsToBounds = YES;
                boxImage.image = [UIImage imageNamed:@"头部背景"];
                [cell addSubview:boxImage];
                
                UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenX375(139) - 0.5, SCREEN_WIDTH, 0.5)];
                line.backgroundColor = LineColor;
                [cell addSubview:line];
            }
            return cell;
        }else {
            static NSString *cellId = @"detailCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(100), ScreenX375(44))];
                noteLabel.text = @"材质描述：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), SCREEN_WIDTH - ScreenX375(26), ScreenX375(112))];
                textView.layer.cornerRadius = ScreenX375(5);
                textView.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
                textView.layer.borderWidth = 0.5;
                textView.clipsToBounds = YES;
                [cell addSubview:textView];
            }
            return cell;
        }
    }
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section < 3) {
        return 0.01;
    }else {
        if (indexPath.row == 0) {
            return ScreenX375(139);
        }
        return ScreenX375(160);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section < 3) {
        return ScreenX375(53);
    }
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section < 3) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(53))];
        view.backgroundColor = [UIColor whiteColor];
        
        UIView *rline = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenX375(15), ScreenX375(3), ScreenX375(23))];
        rline.backgroundColor = ThemeColor;
        [view addSubview:rline];
        
        NSArray *noteArr = @[@"层数",@"材质",@"楞型"];
        UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(300), ScreenX375(24))];
        noteLabel.text = noteArr[section];
        noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
        noteLabel.font = Kfont(18);
        [view addSubview:noteLabel];
        
        UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(39), 0, ScreenX375(39), ScreenX375(53))];
        [selectBtn setImage:[UIImage imageNamed:@"矢量智能对象拷贝2副本2"] forState:UIControlStateNormal];
        //        [selectBtn addTarget:self action:@selector(selectBoxType) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:selectBtn];
        
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(53) - 0.5, SCREEN_WIDTH, 0.5)];
        line.backgroundColor = LineColor;
        [view addSubview:line];
        
        return view;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
